package com.clkj.nangang.mvp.index.appeal;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.clkj.nangang.R;
import com.clkj.nangang.app.CustomApplication;
import com.clkj.nangang.common.Constant;
import com.clkj.nangang.mvp.base.BaseActivity;
import com.clkj.nangang.util.CommonUtil;
import com.clkj.nangang.util.schedulers.SchedulerProvider;

public class AddAppealActivity extends BaseActivity implements AppealContract.View {

    private TextView tvReport;
    private TextView tvLinkphone;
    private EditText etAppeal;
    private TextView tvSubmit;

    private AppealContract.Presenter presenter;
    private String personId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_appeal);
        initTitle(null, null, "生活诉求", true, null);
        initView();
        initData();
        assignView();
    }

    @Override
    public void initData() {

        presenter = new AppealPresenter(this, SchedulerProvider.getInstance(), CustomApplication.getInstance().getHttpService());

        personId = (String) CommonUtil.getShareValue(Constant.NANGAN_USERID, "");
    }

    @Override
    public void assignView() {

        tvReport.setText("反  映  人:" + CommonUtil.getShareValue(Constant.NANGAN_NAME, ""));
        tvLinkphone.setText("联系方式:" + CommonUtil.getShareValue(Constant.NANGAN_PHONE, ""));

        //提交诉求
        tvSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String report = etAppeal.getText().toString();
                if (TextUtils.isEmpty(report)) {
                    Toast.makeText(AddAppealActivity.this, "请输入诉求", Toast.LENGTH_SHORT).show();
                    return;
                }

                presenter.submitAppeal(personId, report);
            }
        });

    }

    @Override
    public void initView() {

        tvReport = (TextView) findViewById(R.id.tv_report);
        tvLinkphone = (TextView) findViewById(R.id.tv_linkphone);
        etAppeal = (EditText) findViewById(R.id.et_appeal);
        tvSubmit = (TextView) findViewById(R.id.tv_submit);
    }

    @Override
    public void onNetError(String tip) {
        Toast.makeText(this, tip, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void submitAppealSuccess(String tip) {
        Toast.makeText(this, tip, Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void submitAppealFail(String tip) {
        Toast.makeText(this, tip, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void setPresenter(AppealContract.Presenter presenter) {
        this.presenter = presenter;
    }
}
